export default {
	//数据
	data() {
		return {
      userInfo: this.get("userInfo"), //用户信息
		  thatUrl: this.urls.baseUrl,
			baseData: [], // 基地展示数据
      announcementTotal: 0, //通知公告总条数
      announcementPage: 1, //通知公告当前页
      announcementSize: 10, //通知公告每页显示条数

      achievementTotal: 0, //成果总条数
      achievementPage: 1, //成果当前页
      achievementSize: 2, //成果每页显示条数

      workDynamicTotal: 0, //工作动态总条数
      workDynamicPage: 1, //工作动态当前页
      workDynamicSize: 3, //工作动态每页显示条数

      briefingTotal: 0, //简报总条数
      briefingPage: 1, //简报当前页
      briefingSize: 2, //简报每页显示条数

			fatherIndex: 0, //一级菜单默认index
			childIndex: 0, //二级级菜单默认index
			loginShow: true, //登录条默认显示
			userShow: false, //用户信息默认隐藏
			portalConfigList: [], //门户列信息
			portalMainImgUrl: "", //门户主图
			portalSecondImgUrl: "", //门户次图
			announcementList: [], //通知公告列表信息
			achievementList: [], //成果列表信息
			workDynamicList: [], //动态列表信息
      briefingList: [], //简报列表信息
      mailContent: '',//邮件内容
			requrstData: {
				token: this.get("token"), //token
				userRole: this.get("role"), //角色信息
				userInfo: this.get("userInfo"), //用户信息
				data: null
			}, //接口参数
			/*菜单列表*/
			items: [{
					id: "1",
					name: '首页',
					isSubShow: false,
					path: "/index"
				},
				{
					id: "2",
					name: '相关政策',
					isSubShow: false,
					path: "",
					subItems: [{
						name: '国家政策',
						path: "/nationalPolicy"
					}, {
						name: '地方政策',
						path: "/localPolicy"
					}]
				},
				{
					id: "3",
					name: '资料下载',
					isSubShow: false,
					path: "/dataDownload",
				},
				{
					id: "4",
					name: '专家展示',
					isSubShow: false,
					path: "/expertsShow"
				},
				{
					id: "5",
					name: '关于我们',
					isSubShow: false,
					path: "/aboutUs"
				},
			],
		}
	},
	created() { //调用方法
		let that = this;
		//判断用户是否登录
		if(this.requrstData != null && this.requrstData.token) {
			this.loginShow = false; //登录条
			this.userShow = true; //用户信息
		}

		//初始化友情连接信息
		that.$post(
				that.urls.getAllPortalConfigList, {
					"type": 1
				}
			)
			.then(function(res) {
				if(res.success) {
					that.portalConfigList = res.data;
				}
			})

		//初始化门户图片信息
		that.$post(
			that.urls.getAllPortalConfigList, {
				"type": 0
			}
		)
		.then(function(res) {
			if(res.success) {
				let portalConfigList = res.data;
				for(let i = 0, len = portalConfigList.length; i < len; i++) {
					if(portalConfigList[i].baseType == 0) {
						that.portalMainImgUrl = portalConfigList[i].url; //门户主图
					} else if(portalConfigList[i].baseType == 1) {
						that.portalSecondImgUrl = portalConfigList[i].url; //门户次图
					}
				}
			}
		})

		//初始化通知公告分页数据
		that.$post(
				that.urls.getAnnouncementPageInfo, {
					"pageNum": that.announcementPage,
					"pageSize": that.announcementSize
				}
			)
			.then(function(res) {
				if(res.success) {
					that.announcementList = res.pageInfo.list;
          that.announcementTotal = res.pageInfo.total;
          that.announcementPage = res.pageInfo.pageNum;
				}
			})

		//初始化成果分页数据
		that.$post(
				that.urls.getAchievementPageInfo, {
					"pageNum": that.achievementPage,
					"pageSize": that.achievementSize
				}
			)
			.then(function(res) {
				if(res.success) {
					//that.achievementList = res.pageInfo.list;
          //that.achievementTotal = res.pageInfo.total;
          //that.achievementPage = res.pageInfo.pageNum;
				}
			})
		//初始化工作动态
		that.$post(
				that.urls.getWorkDynamicPageInfo, {
					"pageNum": that.workDynamicPage,
					"pageSize": that.workDynamicSize
				}
			)
			.then(function(res) {
				if(res.success) {
					that.workDynamicList = res.pageInfo.list;
          that.workDynamicTotal = res.pageInfo.total;
          that.workDynamicPage = res.pageInfo.pageNum;
				}
			})
    //初始化简报
    that.$post(
      that.urls.getBriefingPageInfo, {
        "pageNum": that.briefingPage,
        "pageSize": that.briefingSize
      }
    )
      .then(function(res) {
        if(res.success) {
          that.briefingList = res.pageInfo.list;
          that.briefingTotal = res.pageInfo.total;
          that.briefingPage = res.pageInfo.pageNum;
        }
      })
		//初始化访问量
		that.$post(
				that.urls.addAccessRecord
			)
			.then(function(res) {})

	},
	mounted() {
		let that = this;
		// 基地展示数据
		that.$post(
			that.urls.basePage, {
				"pageNum": 0,
				"pageSize": 4 ,"list": [1,2,5]
			}
		)
		.then(function(res) {
			if(res.success) {
				that.baseData = res.pageInfo.list;
			}
		})
		if(that.userInfo){
			if(that.userInfo.headPortrait != ' ' && that.userInfo.headPortrait){
		      $('#headImg').attr('src', that.urls.baseUrl + that.userInfo.headPortrait)
		    }
		}
	    
	},
	updated:function(){
		if(this.getParamValue("fatherIndex")){
			this.fatherIndex=this.getParamValue("fatherIndex");
		}
		if(this.getParamValue("childIndex")){
			this.childIndex=this.getParamValue("childIndex");
		}
	},
	methods: { //写函数方法
		
		//跳转到管理中心
		goManagementCenter:function(){
			let that = this;
			that.$post(
				that.urls.findMenuByRole, {
					roleId: that.get("userRole") != null ? that.get("userRole").id : null,
					Authorization: that.token
				}
			)
			.then(function(res) {
				if(res.success) {
					that.items = res.data;
					if(that.items.length){
						window.location="/#/"+that.items[0].url+"?fatherIndex=0";
					}else{
						layer.msg('管理中心无菜单', {
							time: 3000, //3s后自动关闭
						});
					}

				} else {
					layer.alert(res.message);
				}
			})
			.catch(function(err) {
				if(err.response) {
					console.log(err.response)
					//控制台打印错误返回的内容
					layer.msg('失败！', {
						time: 3000, //3s后自动关闭
					});
				}
			})
		},
		//用户下拉信息鼠标事件
		showUl: function() {
			$(".wkp-right>div>ul").css("display", "block");
		},
		leaveDiv: function() {
			$(".wkp-right>div>ul").css("display", "none");
		},
		/*菜单切换*/
		showToggle: function(ind, item) {
			this.fatherIndex = ind;
			if(item.subItems){
				this.$router.push({
					path: item.subItems[0].path+"?fatherIndex="+ind+"&childIndex=0"
				})
			}else{
				this.$router.push({
					path: item.path+"?fatherIndex="+ind
				})
			}
			

		},
		clickChild: function(ind,inds, subItem) {
			this.childIndex = inds;
			this.$router.push({
				path: subItem.path+"?fatherIndex="+ind+"&childIndex="+inds
			})
		},
    tempMsgTips: function() {
      layer.msg("维护中......", {
        time: 3000, //3s后自动关闭
      });
    },
    //发送邮件
    sendMail: function() {
      let that = this;
      let contenLen = this.mailContent.length;
      if (contenLen == 0) {
        layer.msg("请填写反馈问题！", {
          time: 3000, //3s后自动关闭
        });
      } else if (contenLen > 100) {
        layer.msg("反馈内容最多只能输入100个字！", {
          time: 3000, //3s后自动关闭
        });
      } else {
        this.$post(
          this.urls.sendSimpleMail,
          {"content": this.mailContent}
        )
        .then(function(res) {
          let msg = "";
          if(res.success) {
            msg = "反馈成功！";
            //清空反馈内容
            that.mailContent = "";
          } else {
            msg = "反馈失败！";
          }
          layer.msg(msg, {
            time: 3000, //3s后自动关闭
          });
        })
      }
    },
    //跳转到登录页面
    gotoIndex: function() {
      this.$router.push({
        path: "index",
      })
    },
		//通知公告详情页
		ResultsNavBox: function(uuid) {
			if(uuid != null && uuid != "") {
				this.set("Announcementsid", uuid);
				this.$router.push({
					path: "WorkingDynamicDetails?fatherIndex="+this.fatherIndex,
				})
			}
		},
		//动态详情页
		WorkingDynamicDetails: function(uuid) {
			if(uuid != null && uuid != "") {
				this.set("WorkingDynamicDetailsid", uuid);
				this.$router.push({
					path: "NewsDetails?fatherIndex="+this.fatherIndex,
				})
			}
		},
		//成果详情
		resultsDetails: function(uuid) {
			if(uuid != null && uuid != "") {
				this.set("briefingsUuid", uuid);
				this.$router.push({
					path: "workBriefingDetail?fatherIndex="+this.fatherIndex,
				})
			}
		},
		//基地详情
		baseDetails: function(id) {
			this.set("baseDetailsid", id);
			this.$router.push({
				path: "baseDetails?fatherIndex="+this.fatherIndex,
			})
		},
		//退出登录
		logOut: function() {
			var that = this;
			that.clear(); //token
			that.loginShow = true;
			that.userShow = false;
			that.$router.push({
				path: "login",
			})

		},
		/*关闭培训悬浮框*/
		closeTraining:function(){
			$(".training-enrolment").css("display","none");
		},
		/*跳转到培训登录页面*/
		toLoginTraining:function(){
			this.$router.push({
				path: "TheTraining",
			})
		}
	}
}
